#!/usr/bin/python
from HTMLParser import HTMLParser
import urllib

class MyHTMLParser(HTMLParser):
    list = []
    url_spider = None

    def set_url(self,url):
	self.url_spider = url
 
    def handle_starttag(self, tag, attrs):
	if str(tag) == 'a':
		url =  str(attrs[0][1])
		if url.find("http") >= 0:
			pass
		else:
			if url.startswith("/"):
				url = self.url_spider+url
			else:
				url = self.url_spider+"/"+url
		self.list.append(url)
	
    def handle_endtag(self, tag):
	pass

    def return_list(self):
	return self.list


class Get_urls():
	url_to_spider=None

	def __init__(self,url):
		self.url_to_spider=url

	def get_urls(self):
		a = MyHTMLParser()
		a.set_url(self.url_to_spider)
		if not self.url_to_spider == None:
			data = urllib.urlopen(self.url_to_spider)
			f = open("/home/huzaifas/file.html","w")	
			f.write(data.read())
			f.close()
			a.feed(open("/home/huzaifas/file.html").read())
			list = a.return_list()
			return list


